package com.zxl.yjb.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zxl.yjb.GlideApp;
import com.zxl.yjb.R;
import com.zxl.yjb.bean.OrderTakeBean;
import com.zxl.yjb.http.HostUrl;

import java.util.List;

public class OrderTakeAdapter extends BaseQuickAdapter<OrderTakeBean, BaseViewHolder> {


    private final int order_status;
    private final int pay_status;

    public OrderTakeAdapter(int layoutResId, @Nullable List<OrderTakeBean> data, int order_status, int pay_status) {
        super(layoutResId, data);
        this.order_status = order_status;
        this.pay_status = pay_status;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderTakeBean item) {
        helper.setText(R.id.tv_order_title, item.getCat_type_name()+"_"+item.getServer_name())
                .setText(R.id.tv_order_time, item.getEnd_time())
                .setText(R.id.tv_order_id, item.getOrder_sn())
                .setText(R.id.tv_order_time, item.getStart_time())
                .setText(R.id.tv_order_amount, TextUtils.isEmpty(item.getOrder_amount())?"未知价格":(item.getOrder_amount()+"元"));
        ImageView headImg = helper.getView(R.id.iv_head_img);
        GlideApp.with(mContext).load(HostUrl.HOSTPIC +item.getFace_img()).into(headImg);
        helper.addOnClickListener(R.id.iv_head_img);
        if (item.getHaveread() == 1)
        {
            helper.getView(R.id.iv_isread).setVisibility(View.GONE);
        }
        else
        {
            helper.getView(R.id.iv_isread).setVisibility(View.VISIBLE);
        }
        if (order_status == 2 && pay_status == 1) {//已完工

            helper.setVisible(R.id.tv_order_time,false);
            helper.setVisible(R.id.tv_order_amount,true);
            helper.setVisible(R.id.btn_comment, true);

            helper.setVisible(R.id.idcode,false);
            helper.setText(R.id.tv_order_id,item.getStart_time());

            /*if (item.getHasevaluate() == 0) {//没有评论
                helper.setBackgroundRes(R.id.btn_comment, R.drawable.btn_submit)
               .addOnClickListener(R.id.btn_comment)
               .setChecked(R.id.btn_comment, true);
            }else {
                helper.setBackgroundRes(R.id.btn_comment, R.drawable.btn_cancel);
                helper.setChecked(R.id.btn_comment, false);
            }*/
            if (TextUtils.isEmpty(item.getEvaluate_id_by_response())) {//没有评论
                helper.setBackgroundRes(R.id.btn_comment, R.drawable.btn_submit)
               .addOnClickListener(R.id.btn_comment)
               .setChecked(R.id.btn_comment, true)
                .setVisible(R.id.btn_comment,true);
            }else {
                helper.setBackgroundRes(R.id.btn_comment, R.drawable.btn_cancel);
                helper.setChecked(R.id.btn_comment, false);
                helper.setVisible(R.id.btn_comment,false);
            }
        }else {
            helper.setVisible(R.id.btn_comment, false);
        }

        if (order_status == 1 && pay_status == 1)//服务中
        {
            helper.setVisible(R.id.tv_order_time,false);
            helper.setVisible(R.id.tv_order_amount,true);

            helper.setVisible(R.id.idcode,false);
            helper.setText(R.id.tv_order_id,item.getStart_time());
        }

    }
}
